﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Arm2015.Storage
{
    public static class Fact
    {
        public static IQueryable<Models.Fact.Month> D_MONTHES
        {
            get
            {
                var context = new DataEntities();

                var results = context.D_MONTH.Select(x => new Models.Fact.Month {
                    C_MONTH=x.C_MONTH,
                    N_MONTH=x.N_MONTH,
                    YEAR=x.YEAR,
                    NUM_MONTH=x.MONTH_NUM
                });

                return results;
            }
        }

        public static IQueryable<Models.Fact.Maker> D_MAKERS
        {
            get
            {
                var context = new DataEntities();

                var results = context.D_MAKER.Select(x => new Models.Fact.Maker
                {
                    C_CONTRACTOR = x.C_CONTRACTOR,
                    C_MAKER = x.C_MAKER,
                    N_MAKER = x.DISPLAY_NAME,
                    IS_ACTIVE = x.IS_ACTIVE == 1 ? true : false
                });

                return results;
            }
        }

        public static IQueryable<Models.Fact.Object> D_OBJECTS
        {
            get
            {
                var context = new DataEntities();

                var results = context.D_OBJECT_CONTRACT
                    .Select(x => new Models.Fact.Object
                    {
                        C_CONTRACT = x.C_CONTRACT,
                        C_OBJECT = x.C_OBJECT,
                        CODE = x.D_OBJECT.CODE,
                        N_OBJECT = x.D_OBJECT.OBJECT_CAPTION
                    });

                return results;
            }
        }

        public static IQueryable<Models.Fact.ObjectElement> D_ELEMENTS
        {
            get
            {
                var context = new DataEntities();

                var results = context.D_OBJECT_ELEMENT.Select(x => new Models.Fact.ObjectElement {
                    C_OBJECT_ELEMENT=x.C_OBJECT_ELEMENT,
                    LOCATION=x.LOCATION,
                    BEGKM=x.BEGKM,
                    ENDKM=x.ENDKM,
                    C_OBJECT=x.C_OBJECT,
                    C_ELEMENT=x.C_ELEMENT,
                    N_ELEMENT=x.S_ELEMENT.N_ELEMENT,
                    C_TYPE_ELEMENT=x.S_ELEMENT.C_TYPE_ELEMENT,
                    N_TYPE_ELEMENT=x.S_ELEMENT.S_TYPE_ELEMENT.N_TYPE_ELEMENT
                });
                return results.Distinct();
            }
        }
    }
}
